
import pytest
import csv

from selenium import webdriver
from time import sleep

from selenium.webdriver.common.by import By

def get_data():
    with open('test.csv',encoding="utf-8") as f:
        lst = csv.reader(f)
        my_data = []
        for row in lst:
            my_data.append(row)
    return my_data


class TestCase(object):
    driver = webdriver.Chrome()
    @pytest.mark.parametrize("name", get_data())
    def testLogin(self,name):
        self.driver.get("http://10.215.56.131:8002/#/ai-home")
        self.driver.maximize_window()
        username = name[0]
        password = name[1]
        expected = name[2]
        sleep(1)
        self.driver.find_element(By.XPATH,'//*[@id="guimi-home"]/body/section[1]/div/button/span').click()
        sleep(1)
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[1]/div/div/input').clear()
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[1]/div/div/input').send_keys(username)
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[2]/div/div/input').clear()
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[2]/div/div/input').send_keys(password)
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[4]/button/span').click()
        sleep(2)
        actual = self.driver.find_element(By.XPATH,"/html/body/div[2]/p")
        text = actual.text
        assert text == expected

if __name__ == '__main__':
    pytest.main(["testDdt.py"])